package com.lanswon.qzsmk.controller.inventoryManageController;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.annotation.SystemControllerLog;
import com.lanswon.qzsmk.base.DwzPage;
import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfReceiveBFByCenter")
public class InventoryMagOfReceiveBFByCenterController {
	
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfReceiveBFByCenterController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	/**
	 * 子模块：中心库接收空白卡/成品卡上缴 
	 * 跳转网点接收页面
	 * @return
	 */
	@RequiresPermissions("inventoryMagOfReceiveBFByCenter:index")
	@RequestMapping(name = "空白卡上缴接收登记页面,inventoryMagOfReceiveBFByCenter:index",value = "/queryBlankAndFinishCardReceiving", method = { RequestMethod.POST, RequestMethod.GET })
	@SystemControllerLog(description = "跳转网点接收页面")
	public String queryBlankAndFinishCardReceiving(HttpServletRequest request) {

		return "BlankAndFinishCardReceiving";
	}
	
	/**
	 * 子模块：接收上缴入库
	 * 网点接收页面加载
	 * @return
	 */
	@RequiresPermissions("inventoryMagOfReceiveBFByCenter:getBlankAndFinishCardReceiving")
	@RequestMapping(name = "查询空白卡信息,inventoryMagOfReceiveBFByCenter:getBlankAndFinishCardReceiving",value = "/getBlankAndFinishCardReceiving", method = RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "网点接收页面加载")
	public Map<String, Object> getBlankAndFinishCardReceiving(HttpServletRequest request, Integer currentPage, Integer numPerPage) {
		if (currentPage == null && numPerPage == null) {
			currentPage = 1;
			numPerPage = 10;
		}
		// 接收前画面穿过来数据
		String distributeTaskNo = request.getParameter("blankDistributeTaskNoByReceiving");
		// 装有画面信息的map
		Map<String, String> map = new HashMap<String, String>();
		map.put("distributeTaskNo", distributeTaskNo);
		DwzPage<Map<String,String>> dpList = ims.getBlankAndFinishCardReceiving(map, currentPage, numPerPage);
		Map<String, Object> rMap = new HashMap<>();
		rMap.put("list", dpList);
		rMap.put("distributeNo", distributeTaskNo);
		return rMap;
	}
	
	/**
	 * 子模块：接收空白卡入库登记
	 * 提交信息
	 * @param request
	 * @return
	 */
	@RequiresPermissions("inventoryMagOfReceiveBFByCenter:blankAndRejectCardReceivingRegister")
	@RequestMapping(name = "空白卡接收入库,inventoryMagOfReceiveBFByCenter:blankAndRejectCardReceivingRegister",value = "/blankAndRejectCardReceivingRegister", method = RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "提交信息")
	public Map<String, Object> blankAndFinishCardReceivingRegister(String[] blankCardReceivingtasked,HttpServletRequest request) {
		// 前画面组装成的参数
		String[] paramString = blankCardReceivingtasked;
		String storageModeByTurnIn = request.getParameter("storageModdeByTurnIn");
		logger.debug("前画面传递的参数==>" + paramString);
		String checkedeParam = null;
		for (int i = 0; i < paramString.length; i++) {
			if (i == 0) {
				checkedeParam = paramString[0];
			} else {
				checkedeParam = checkedeParam + "$" + paramString[i];
			}
		}
		logger.debug("选中的参数有===>" + checkedeParam);
		// 打印参数的组装map
		Map<String, Object> rMap = null;
		rMap = ims.BlankAndRejectCardReceivingRegist(checkedeParam,storageModeByTurnIn);

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("applyType", rMap.get("credential_type"));
		Map<String, Object> map = new HashMap<>();
		map.put("ipAddress", rMap.get("ipAddress"));
		map.put("storageNo", rMap.get("storageNo"));
		map.put("max", "true");
		map.put("title", rMap.get("title"));
		map.put("rel", "receiveTask");
		map.put("statusCode", "200");
		map.put("message", "上缴接收成功");
		map.put("param", paramMap);
		map.put("url", "printCredentials/toStoragePdfView");
		
		if("03".equals(storageModeByTurnIn)){
			map.put("jumpToTile", "废卡/注销卡上缴接收");
			map.put("jumpToTabid", "queryRejectCardReceiving");
			map.put("jumpToUrl", "inventoryMagOfReceiveRejectCardByCenter/queryRejectCardReceiving");
		}else if("04".equals(storageModeByTurnIn)){
			map.put("jumpToTile", "空白卡/成品卡上缴接收");
			map.put("jumpToTabid", "queryCardReceiving");
			map.put("jumpToUrl", "inventoryMagOfReceiveBFByCenter/queryBlankAndFinishCardReceiving");
		}
		return map;
	}
	
}
